package de.wowrealmstatus.types;

public enum Population {
	Low,
	Medium,
	High,
	Unknown;
	
	public static Population getPopulation (Object object) {
		int num = 0;
		if (object instanceof Integer) {
			num = (Integer) object;
		} else if (object instanceof String) {
			try {
				num = Integer.parseInt((String) object);
			} catch (NumberFormatException nfe) {
				return getByString((String)object);
			}
		}
		if (num != 0) {
			return getByInt(num);
		}
		return Unknown;
	}
	
	private static Population getByInt(int num) {
		switch (num) {
		case 1:
			return Low;
		case 2:
			return Medium;
		case 3:
			return High;
		default:
			return Unknown;
		}
	}
	
	private static Population getByString (String s) {
		if (s == null || s.trim().equals("")) {
			return Medium;
		} else if (s.startsWith("Full")){
			return High;
		} else if (s.startsWith("Recommended")){
			return Low;
		}
		return Unknown;
	}
}
